using System;
using System.Collections.Generic;
using System.Drawing;
using MEA.AE_Data.Config;

namespace MEA.AE_Data
{
	public class LogSignalLiveView : LogSignalBase
	{
		private List<uint> sigValues;

		private int recordInterval_ms;

		private string address;

		private string ecu_Message;

		private EDataType sigType;

		private ushort memSize;

		private EStringFormat numericFormat;

		private uint signalVisiability;

		private ConfigLiveView.ESignals ecu_Emesage;

		public List<uint> SigValues
		{
			get
			{
				return sigValues;
			}
		}

		public int RecordInterval_ms
		{
			get
			{
				return recordInterval_ms;
			}
			set
			{
				recordInterval_ms = value;
			}
		}

		public List<byte> Address
		{
			get
			{
				List<byte> list = new List<byte>();
				if (address.Length != ConfigLiveView.LiveViewAddressLength)
				{
					throw new Exception("Address of signal " + ecu_Message + " not in correct format!");
				}
				int num = 0;
				while (num < address.Length)
				{
					byte b = 0;
					b = (byte)(Convert.ToInt32(address[num].ToString(), 16) * 16 + Convert.ToInt32(address[num + 1].ToString(), 16));
					num += 2;
					list.Add(b);
				}
				return list;
			}
		}

		public EDataType SigType
		{
			get
			{
				return sigType;
			}
		}

		public bool BoostPresTest
		{
			get
			{
				if ((signalVisiability & 0x10) == 16)
				{
					return true;
				}
				return false;
			}
		}

		public bool PropellerSelftest
		{
			get
			{
				if ((signalVisiability & 0x20) == 32)
				{
					return true;
				}
				return false;
			}
		}

		public bool PowerLevelTest
		{
			get
			{
				if ((signalVisiability & 0x80) == 128)
				{
					return true;
				}
				return false;
			}
		}

		public bool RailPresTest
		{
			get
			{
				if ((signalVisiability & 0x40) == 64)
				{
					return true;
				}
				return false;
			}
		}

		public bool DiffAngleTest
		{
			get
			{
				if ((signalVisiability & 0x100) == 256)
				{
					return true;
				}
				return false;
			}
		}

		public bool IsSignalVirtual
		{
			get
			{
				bool result = false;
				if ((signalVisiability & 0x200) == 512)
				{
					result = true;
				}
				return result;
			}
		}

		public bool IsSignalAlwaysVis
		{
			get
			{
				if ((signalVisiability & 0xF) == 1)
				{
					return true;
				}
				return false;
			}
		}

		public bool IsSignalOnlyByDisplayVisible
		{
			get
			{
				if ((signalVisiability & 0xF) == 4)
				{
					return true;
				}
				return false;
			}
		}

		public string ECU_Message
		{
			get
			{
				return ecu_Message;
			}
		}

		public ConfigLiveView.ESignals ECU_EMesage
		{
			get
			{
				return ecu_Emesage;
			}
		}

		public string Ecu_Message
		{
			get
			{
				return ecu_Message;
			}
		}

		public ushort MemSize
		{
			get
			{
				return memSize;
			}
		}

		public EStringFormat NumericFormat
		{
			get
			{
				return numericFormat;
			}
		}

		public bool ExpertModeOnly
		{
			get
			{
				if ((signalVisiability & 0xFF) == 2)
				{
					return true;
				}
				return false;
			}
		}

		public uint Mode
		{
			get
			{
				return signalVisiability & 0xF;
			}
		}

		public string getLiveViewType()
		{
			string text = "";
			if (sigType == EDataType.e_u8)
			{
				return "u8";
			}
			return "f4";
		}

		public LogSignalLiveView(string description, string ECU_Message, EDataType type, ELiveViewSigClass sigClass, EStringFormat format, float Ymin, float Ymax, Color color)
			: base(description, sigClass, format, Ymin, Ymax, color)
		{
			sigValues = new List<uint>();
			recordInterval_ms = 100;
			ecu_Message = ECU_Message;
			sigType = type;
			address = "FFFFFF";
			base.sigClass = sigClass;
			switch (type)
			{
			case EDataType.e_u8:
			case EDataType.e_s8:
				memSize = 1;
				break;
			case EDataType.e_u16:
			case EDataType.e_s16:
				memSize = 2;
				break;
			case EDataType.e_u32:
			case EDataType.e_s32:
				memSize = 4;
				break;
			default:
				memSize = 1;
				break;
			}
		}

		public void addMSGEnum(ConfigLiveView.ESignals m)
		{
			ecu_Emesage = m;
		}

		public void SetAddLogSignalLiveView(string address)
		{
			this.address = address;
		}

		public void SetVisiabilityLiveViewSig(uint visiability)
		{
			signalVisiability = visiability;
		}

		public void ConfigureAuxSignal(string address, int msgLength)
		{
			if (address.Length == ConfigLiveView.LiveViewAddressLength)
			{
				this.address = address;
				if (msgLength < 1 || msgLength > 4 || msgLength == 3)
				{
					throw new Exception("byte length of AUX signal incorrect");
				}
				memSize = (ushort)msgLength;
				switch (msgLength)
				{
				case 1:
					sigType = EDataType.e_u8;
					format = EStringFormat.e_X2;
					numericFormat = EStringFormat.e_X2;
					Ymax = (float)Math.Pow(2.0, 8.0) - 1f;
					break;
				case 2:
					sigType = EDataType.e_u16;
					format = EStringFormat.e_X4;
					numericFormat = EStringFormat.e_X4;
					Ymax = (float)Math.Pow(2.0, 16.0) - 1f;
					break;
				case 4:
					sigType = EDataType.e_u32;
					format = EStringFormat.e_X8;
					numericFormat = EStringFormat.e_X8;
					Ymax = (float)Math.Pow(2.0, 32.0) - 1f;
					break;
				default:
					sigType = EDataType.e_u16;
					format = EStringFormat.e_X4;
					numericFormat = EStringFormat.e_X4;
					Ymax = (float)Math.Pow(2.0, 16.0) - 1f;
					break;
				}
				if ((Ymax - Ymin) / 10f > 0f)
				{
					Yscal = (Ymax - Ymin) / 10f;
				}
				else
				{
					Yscal = 1.0;
				}
				return;
			}
			throw new Exception("address length of AUX signal incorrect");
		}
	}
}
